home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / QuickTime™ IC SDK 1.01 / Sample Code / QTICSamplePanel / QTICSamplePanel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-23  |  21.9 KB  |  761 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        QTICSamplePanle.c
  3.  
  4.     Contains:    QTIC Sample Panel.
  5.  
  6.     Written by:    Dino Tang
  7.  
  8.     Copyright:    © 1996-1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        04/25/97    DT        First created.
  13.  
  14.     To Do:
  15.  
  16. */
  17.  
  18. #include    <Types.h>
  19. #include    <Errors.h>
  20. #include    <Memory.h>
  21. #include    <Resources.h>
  22. #include    <TextUtils.h>
  23. #include    <QDOffscreen.h>
  24. #include    <TextUtils.h>
  25.  
  26. #include    "QTICSamplePanel.h"
  27.  
  28. /* ------------------------------------------------------------------------- */
  29.  
  30. RoutineDescriptor MainRD = BUILD_ROUTINE_DESCRIPTOR(uppMainProcInfo, QTICSAMPLEPANEL);
  31.  
  32. /* ------------------------------------------------------------------------- */
  33.  
  34. pascal Boolean DLOGU_anyClickDialogFilter(DialogRef theDialog, EventRecord *theEvent, short *itemHit);
  35. void PANELU_LoadStringFromRsrc( short id, short maxSize, unsigned char *str, unsigned char *defaultStr);
  36.  
  37. /* ------------------------------------------------------------------------- */
  38.  
  39. //    Component entry point.
  40.  
  41. pascal ComponentResult QTICSAMPLEPANEL(ComponentParameters *params, char **storage)
  42. {
  43.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  44.     
  45.     if ( params->what < 0 ) { 
  46.         switch ( params->what ) {
  47.             case kComponentOpenSelect:
  48.                 return ( CallComponentFunctionUniv(params, QTICP_Open) );
  49.             case kComponentCloseSelect:
  50.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Close) );
  51.             case kComponentCanDoSelect:
  52.                 return ( CallComponentFunctionUniv(params, QTICP_CanDo) );
  53.             case kComponentTargetSelect:
  54.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Target) );
  55.             case kComponentVersionSelect: 
  56.                 return ( kQTICPanelVersion );
  57.             default:
  58.                 return ( unimpErr );
  59.         }
  60.     } else {
  61.         switch ( params->what ) {
  62.             case kQTICPAboutBoxSelect:
  63.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_AboutBox) );
  64.             case kQTICPInitializeSelect:
  65.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Initialize) );
  66.             case kQTICPSetControlsSelect:
  67.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_SetControls) );
  68.             case kQTICPGetSettingsSelect:
  69.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_GetSettings) );
  70.             case kQTICPSetSettingsSelect:
  71.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_SetSettings) );
  72.             case kQTICPCanUseCameraSelect:
  73.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_CanUseCamera) );
  74.  
  75.             case kQTICPIsPanelSelect:
  76.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_IsPanel) );
  77.             case kQTICPCloseWindowSelect:
  78.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_CloseWindow) );
  79.             case kQTICPEventSelect:
  80.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Event) );
  81.             case kQTICPIdleSelect:
  82.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Idle) );
  83.             case kQTICPInContentDoubleSelect:
  84.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_InContentDouble) );
  85.             case kQTICPInContentSelect:
  86.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_InContent) );
  87.             case kQTICPGetGrowSizeSelect:
  88.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_GetGrowSize) );
  89.             case kQTICPGrowWindowSelect:
  90.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_GrowWindow) );
  91.             case kQTICPZoomWindowSelect:
  92.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_ZoomWindow) );
  93.             case kQTICPDoKeyDownSelect:
  94.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_DoKeyDown) );
  95.             case kQTICPDrawSelect:
  96.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Draw) );
  97.             case kQTICPUpdateCustomMenuSelect:
  98.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_UpdateCustomMenu) );
  99.             case kQTICPDoCustomMenuSelect:
  100.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_DoCustomMenu) );
  101.             case kQTICPGetMenuNameSelect:
  102.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_GetMenuName) );
  103.             case kQTICPFinishCustomMenuSelect:
  104.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_FinishCustomMenu) );
  105.             case kQTICPActivateSelect:
  106.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Activate) );
  107.             case kQTICPDeactivateSelect:
  108.                 return ( CallComponentFunctionWithStorageUniv(storage, params, QTICP_Deactivate) );
  109.  
  110.             default:
  111.                 return ( unimpErr );
  112.         }
  113.     }
  114. }
  115.  
  116. /* ------------------------------------------------------------------------- */
  117.  
  118. //    Required component calls.
  119.  
  120. pascal ComponentResult QTICP_Open(ComponentInstance self)
  121. {
  122.     PrivateGlobals         **myPrivateGlobals;
  123.  
  124.     myPrivateGlobals = nil;
  125.  
  126.     //    Create private variables.
  127.     myPrivateGlobals = (PrivateGlobals **) NewHandleClear(sizeof(PrivateGlobals));
  128.     if ( myPrivateGlobals == nil )
  129.         goto bail;
  130.     MoveHHi((Handle) myPrivateGlobals);
  131.     HLock((Handle) myPrivateGlobals);
  132.     
  133.     //    Initialize private variables.
  134.     (**myPrivateGlobals).delegate = 0;
  135.     (**myPrivateGlobals).self = self;
  136.     (**myPrivateGlobals).controls = nil;
  137.     (**myPrivateGlobals).callback = nil;
  138.  
  139.     (**myPrivateGlobals).window = nil;
  140.         
  141.     //    Since we've gotten here, everythings ok and we can set up the connection.
  142.     SetComponentInstanceStorage(self, (Handle) myPrivateGlobals);
  143.  
  144.     return ( kQTIC_noErr );
  145.  
  146. bail:
  147.     if ( myPrivateGlobals != nil ) {
  148.         DisposeHandle((Handle) myPrivateGlobals);
  149.         myPrivateGlobals = nil;
  150.     }
  151.  
  152.     return ( kQTIC_memFullErr );
  153. }
  154.  
  155. pascal ComponentResult QTICP_Close(Handle storage, ComponentInstance self)
  156. {
  157.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  158.     
  159.     //    Dispose of private variables.
  160.     if ( myPrivateGlobals != nil ) {
  161.         //    This clears our controls callbacks.
  162.         if ( (**myPrivateGlobals).controls != nil && (**myPrivateGlobals).callback != nil ) {
  163.             QTICCRemoveActionFilter((**myPrivateGlobals).controls, (**myPrivateGlobals).callback, (long) myPrivateGlobals);
  164.             DisposeRoutineDescriptor((**myPrivateGlobals).callback);
  165.             (**myPrivateGlobals).callback = nil;
  166.         }
  167.  
  168.         //    Put the stuff you need to dispose for your panel here.
  169.         if ( (**myPrivateGlobals).window != nil )
  170.             DisposeWindow((**myPrivateGlobals).window);
  171.             
  172.         DisposeHandle((Handle) myPrivateGlobals);
  173.     }
  174.  
  175.     return ( kQTIC_noErr );
  176. }
  177.  
  178. pascal ComponentResult QTICP_CanDo(short selector)
  179. {
  180.     switch ( selector ) {
  181.         case kComponentOpenSelect:
  182.         case kComponentCloseSelect:
  183.         case kComponentCanDoSelect:
  184.         case kComponentVersionSelect:
  185.         case kComponentTargetSelect:
  186.  
  187.         case kQTICPInitializeSelect:
  188.         case kQTICPAboutBoxSelect:
  189.         case kQTICPGetSettingsSelect:
  190.         case kQTICPSetSettingsSelect:
  191.         case kQTICPSetControlsSelect:
  192.         case kQTICPCanUseCameraSelect:
  193.  
  194.         case kQTICPIsPanelSelect:
  195.         case kQTICPCloseWindowSelect:
  196.         case kQTICPEventSelect:
  197.         case kQTICPIdleSelect:
  198.         case kQTICPInContentDoubleSelect:
  199.         case kQTICPInContentSelect:
  200.         case kQTICPGetGrowSizeSelect:
  201.         case kQTICPGrowWindowSelect:
  202.         case kQTICPZoomWindowSelect:
  203.         case kQTICPDoKeyDownSelect:
  204.         case kQTICPDrawSelect:
  205.         case kQTICPUpdateCustomMenuSelect:
  206.         case kQTICPDoCustomMenuSelect:
  207.         case kQTICPGetMenuNameSelect:
  208.         case kQTICPFinishCustomMenuSelect:
  209.         case kQTICPActivateSelect:
  210.         case kQTICPDeactivateSelect:
  211.             return ( true );
  212.         default:
  213.             return ( false );
  214.     }
  215. }
  216.  
  217. pascal ComponentResult QTICP_Target(Handle storage, ComponentInstance self)
  218. {
  219.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  220.  
  221.     if ( myPrivateGlobals == nil )
  222.         return ( kQTIC_paramErr );
  223.  
  224.     //    From now on, self will be the component instance that targeted us.
  225.     (**myPrivateGlobals).self = self;
  226.     
  227.     return ( kQTIC_noErr );
  228. }
  229.  
  230. /* ------------------------------------------------------------------------- */
  231.  
  232. pascal ComponentResult QTICP_AboutBox(Handle storage)
  233. {
  234.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  235.     short                itemHit;
  236.     DialogPtr            myDialog;
  237.     ModalFilterUPP        myRoutine;
  238.     short                resFile;
  239.     short                resFileComp;
  240.  
  241.     if ( myPrivateGlobals == nil )
  242.         return ( kQTIC_paramErr );
  243.     
  244.     resFile = CurResFile();
  245.     resFileComp = OpenComponentResFile((Component) (**myPrivateGlobals).self);
  246.  
  247.     myRoutine = NewModalFilterProc(DLOGU_anyClickDialogFilter);
  248.     myDialog = GetNewDialog(kDLOG_ABOUT, 0, (WindowRef) -1);
  249.     SetGWorld((CGrafPtr) myDialog, GetMainDevice());
  250.     do {
  251.         ModalDialog(myRoutine, &itemHit);
  252.     } while ( (itemHit != ok) );
  253.     DisposeDialog(myDialog);
  254.     DisposeRoutineDescriptor(myRoutine);
  255.  
  256.     CloseComponentResFile(resFileComp);
  257.     UseResFile(resFile);
  258.  
  259.     return ( kQTIC_noErr );
  260. }
  261.  
  262. pascal ComponentResult QTICP_Initialize(Handle storage, Handle settings)
  263. {
  264.     PrivateGlobals             **myPrivateGlobals = (PrivateGlobals **) storage;
  265.     QTICPanelSettings        **standardSettings = (QTICPanelSettings **) settings;
  266.     short                    resFile;
  267.     short                    resFileComp;
  268.     Rect                    boundsRect;
  269.  
  270.     if ( myPrivateGlobals == nil )
  271.         return ( kQTIC_paramErr );
  272.         
  273.     boundsRect.left = 4;
  274.     boundsRect.top = 44;
  275.     boundsRect.bottom = boundsRect.top + 64;
  276.     boundsRect.right = 254;
  277.  
  278.     //    If you need to get any resources stored in the component file, put it between OpenComponentResFile & CloseComponentResFile.
  279.     resFile = CurResFile();
  280.     resFileComp = OpenComponentResFile((Component) (**myPrivateGlobals).self);
  281.  
  282.     PANELU_LoadStringFromRsrc(kSTR_MENUCONNECTED, 255, (**myPrivateGlobals).menuStrConnected, "\pItem 1;(-;Item 2");
  283.     PANELU_LoadStringFromRsrc(kSTR_MENUNOTCONNECTED, 255, (**myPrivateGlobals).menuStrNotConnected, "\p(Item 1;(-;(Item 2");
  284.     
  285.     //    If you need to get any resources stored in the component file, put it between OpenComponentResFile & CloseComponentResFile.
  286.     CloseComponentResFile(resFileComp);
  287.     UseResFile(resFile);
  288.     
  289.     //    Create window.
  290.     (**myPrivateGlobals).window = NewCWindow(nil, &boundsRect, "\pSample", true, noGrowDocProc, (WindowRef) -1L, true, (long) myPrivateGlobals);
  291.     SetGWorld((CGrafPtr) (**myPrivateGlobals).window, GetMainDevice());
  292.  
  293.     //    Use settings values that are only used at initialize time.
  294.     
  295.     //    Settings is nil.  This is usually used when user selects "New".
  296.     if ( standardSettings == nil ) {
  297.  
  298.     //    If settings is not nil, then double check it is the correct settings handle.
  299.     } else if ( (**standardSettings).header.size >= sizeof(QTICSettingsHeader) &&
  300.                 (**standardSettings).header.type == kQTICPanelComponentType &&
  301.                 (**standardSettings).header.subType == '????' &&    //    Fill in your type.
  302.                 (**standardSettings).header.manufacturer == kQTICPComponentManufacturer &&
  303.                 (**standardSettings).header.version <= kQTICPanelVersion ) {
  304.         FSSpec                theFile;
  305.  
  306.         theFile = (**standardSettings).file;
  307.  
  308.         //    Put code here that checks the datatype.
  309.         if ( (**standardSettings).dataType == '????' ) {
  310.         }
  311.     }
  312.  
  313.     //    Call SetSettings for settings changes that may occur after initialization.
  314.     return ( QTICPSetSettings((**myPrivateGlobals).self, settings) );
  315. }
  316.  
  317. pascal Boolean CameraCallBack(QTICControls qtcc, short action, void *param1, void *param2, void *param3, void *param4, long refCon);
  318. pascal Boolean CameraCallBack(QTICControls qtcc, short action, void *param1, void *param2, void *param3, void *param4, long refCon)
  319. {
  320.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) refCon;
  321.     Boolean        ret;
  322.     
  323.     //    Not handled is default
  324.     ret = false;
  325.  
  326.     //    If we aren't initialized, then don't do anything.
  327.     if ( myPrivateGlobals == nil )
  328.         goto done;
  329.     
  330.     //    If it isn't our window, then don't do anything.
  331.     switch ( action ) {
  332.         case kQTICActionFileGetMenuFlags:
  333.         case kQTICActionEditGetMenuFlags:
  334.         case kQTICActionFileSave:
  335.         case kQTICActionFileSaveAs:
  336.         case kQTICActionFileGetInfo:
  337.         case kQTICActionFilePageSetup:
  338.         case kQTICActionFilePrint:
  339.         case kQTICActionEditUndo:
  340.         case kQTICActionEditCut:
  341.         case kQTICActionEditCopy:
  342.         case kQTICActionEditPaste:
  343.         case kQTICActionEditClear:
  344.         case kQTICActionEditSelectAll:
  345.         case kQTICActionEditSelectNone:
  346.             if ( (**myPrivateGlobals).window != (WindowRef) param1 )
  347.                 goto done;
  348.             break;
  349.         default:
  350.             break;
  351.     }
  352.  
  353.     //    OK.  Now, we know that it is our window and that we can handle it.
  354.     switch ( action ) {
  355.         case kQTICActionFileGetMenuFlags:
  356.             if ( param2 != nil ) {    //    param1 is window and param2 is pointer to short
  357.                 *((short *) param2) = 0;
  358.                 ret = true;
  359.             }
  360.         case kQTICActionFileSave:
  361.         case kQTICActionFileSaveAs:
  362.         case kQTICActionFileGetInfo:
  363.         case kQTICActionFilePageSetup:
  364.         case kQTICActionFilePrint:
  365.             ret = true;
  366.             break;
  367.         case kQTICActionEditGetMenuFlags:
  368.             if ( param2 != nil ) {    //    param1 is window and param2 is pointer to short
  369.                 *((short *) param2) = 0;
  370.                 ret = true;
  371.             }
  372.             break;
  373.         case kQTICActionEditUndo:
  374.         case kQTICActionEditCut:
  375.         case kQTICActionEditCopy:
  376.         case kQTICActionEditPaste:
  377.         case kQTICActionEditClear:
  378.         case kQTICActionEditSelectAll:
  379.         case kQTICActionEditSelectNone:
  380.             ret = true;
  381.             break;
  382.         default:
  383.             break;
  384.     }
  385.  
  386. done:
  387.     return ( ret );
  388. }
  389.  
  390. pascal ComponentResult QTICP_SetControls(Handle storage, QTICControls qtcc)
  391. {
  392.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  393.  
  394.     if ( myPrivateGlobals == nil )
  395.         return ( kQTIC_paramErr );
  396.  
  397.     //    If we previously had a callback, then we need to remove it.
  398.     if ( (**myPrivateGlobals).controls != nil && (**myPrivateGlobals).callback != nil ) {
  399.         QTICCRemoveActionFilter((**myPrivateGlobals).controls, (**myPrivateGlobals).callback, (long) myPrivateGlobals);
  400.         DisposeRoutineDescriptor((**myPrivateGlobals).callback);
  401.         (**myPrivateGlobals).callback = nil;
  402.     }
  403.  
  404.     //    Do we have a new controls component?
  405.     if ( qtcc != nil ) {
  406.         (**myPrivateGlobals).callback = NewQTICActionFilterWithRefConProc(CameraCallBack);
  407.         if ( (**myPrivateGlobals).callback != nil ) {
  408.             QTICCInstallActionFilter(qtcc, (**myPrivateGlobals).callback, (long) myPrivateGlobals);
  409.         }
  410.     }
  411.  
  412.     //    Set the controls component.
  413.     (**myPrivateGlobals).controls = qtcc;
  414.     
  415.     return ( kQTIC_noErr );
  416. }
  417.  
  418. pascal ComponentResult QTICP_GetSettings(Handle storage, Handle *settings)
  419. {
  420.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  421.     DateTimeRec            curTime;
  422.  
  423.     if ( myPrivateGlobals == nil || settings == nil )
  424.         return ( kQTIC_paramErr );
  425.  
  426.     //    If you don't have anything that need to be returned, just return an error.
  427.     return ( paramErr );
  428. }
  429.  
  430. pascal ComponentResult QTICP_SetSettings(Handle storage, Handle settings)
  431. {
  432.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  433.     QTICPanelSettings    **standardSettings = (QTICPanelSettings **) settings;
  434.     short                wleftoffset, wtopoffset;
  435.     FSSpec                theFile;
  436.  
  437.     if ( myPrivateGlobals == nil )
  438.         return ( kQTIC_paramErr );
  439.         
  440.     //    settings is nil.  This is usually used when user selects "New".
  441.     if ( standardSettings == nil ) {
  442.  
  443.     //    If settings is not nil, then double check it is the correct settings handle.
  444.     } else if ( (**standardSettings).header.size >= sizeof(QTICSettingsHeader) &&
  445.                 (**standardSettings).header.type == kQTICPanelComponentType &&
  446.                 (**standardSettings).header.subType == '????' &&    //    Fill in your type.
  447.                 (**standardSettings).header.manufacturer == kQTICPComponentManufacturer &&
  448.                 (**standardSettings).header.version <= kQTICPanelVersion ) {
  449.  
  450.         wleftoffset = (**standardSettings).windowLoc.left;
  451.         wtopoffset = (**standardSettings).windowLoc.top;
  452.         theFile = (**standardSettings).file;
  453.  
  454.         //    Put code here that checks the datatype.
  455.         if ( (**standardSettings).dataType == '????' ) {
  456.         }
  457.     }
  458.  
  459.     return ( kQTIC_noErr );
  460. }
  461.  
  462. pascal ComponentResult QTICP_CanUseCamera(Handle storage, QTICControls qtcc)
  463. {
  464.     PrivateGlobals             **myPrivateGlobals = (PrivateGlobals **) storage;
  465.     ComponentDescription    descr;
  466.     QTICCamera                qtc;
  467.  
  468.     if ( myPrivateGlobals == nil || qtcc == 0 )
  469.         return ( (ComponentResult) false );
  470.  
  471.     return ( (ComponentResult) true );    //    USE JUST THIS IF FOR ALL PANELS
  472. }
  473.  
  474. /* ------------------------------------------------------------------------- */
  475.  
  476. pascal ComponentResult QTICP_IsPanel(Handle storage, WindowRef theWindow)
  477. {
  478.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  479.  
  480.     if ( myPrivateGlobals == nil )
  481.         return ( (ComponentResult) false );
  482.  
  483.     if ( (**myPrivateGlobals).window == theWindow )
  484.         return ( (ComponentResult) true );
  485.  
  486.     return ( (ComponentResult) false );
  487. }
  488.  
  489. pascal ComponentResult QTICP_CloseWindow(Handle storage, WindowRef theWindow)
  490. {
  491.     //    This causes the controls component to close out panel instance.
  492.     return ( kQTIC_paramErr );
  493. }
  494.  
  495. pascal ComponentResult QTICP_Event(Handle storage, EventRecord *theEvent)
  496. {
  497.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  498.     CGrafPtr            savePort;
  499.     GDHandle            saveGD;
  500.     Boolean                handled;
  501.     short                windowPart;
  502.     
  503.     if ( myPrivateGlobals == nil || theEvent == nil )
  504.         return ( (ComponentResult) false );
  505.  
  506.     handled = false;
  507.  
  508.     GetGWorld(&savePort, &saveGD);
  509.  
  510.     switch ( theEvent->what ) {
  511.         case mouseDown:
  512.             switch ( windowPart ) {
  513.                 case inContent:
  514.                     break;
  515.                 case inDrag:
  516.                     break;
  517.                 case inGrow:
  518.                     break;
  519.                 case inGoAway:
  520.                     break;
  521.                 case inZoomIn:
  522.                 case inZoomOut:
  523.                     break;
  524.                 default:
  525.                     break;
  526.             }
  527.             break;
  528.         case keyDown:
  529.         case autoKey:
  530.             break;
  531.         case updateEvt:
  532.             break;
  533.         default:
  534.             break;
  535.     }
  536.  
  537.     //    Restore port and device.
  538.     SetGWorld(savePort, saveGD);
  539.             
  540.     return ( (ComponentResult) handled );
  541. }
  542.  
  543. pascal ComponentResult QTICP_Idle(Handle storage)
  544. {
  545.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  546.  
  547.     if ( myPrivateGlobals == nil )
  548.         return ( kQTIC_paramErr );
  549.  
  550.     return ( kQTIC_noErr );
  551. }
  552.  
  553. pascal ComponentResult QTICP_InContentDouble(Handle storage, WindowRef theWindow, EventRecord *theEvent)
  554. {
  555.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  556.     Point                here;
  557.  
  558.     if ( myPrivateGlobals == nil )
  559.         return ( kQTIC_paramErr );
  560.  
  561.     here = theEvent->where;
  562.     GlobalToLocal(&here);
  563.     
  564.     return ( kQTIC_noErr );
  565. }
  566.  
  567. pascal ComponentResult QTICP_InContent(Handle storage, WindowRef theWindow, EventRecord *theEvent)
  568. {
  569.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  570.  
  571.     if ( myPrivateGlobals == nil )
  572.         return ( kQTIC_paramErr );
  573.  
  574.     return ( kQTIC_noErr );
  575. }
  576.  
  577. pascal ComponentResult QTICP_GetGrowSize(Handle storage, WindowRef theWindow, Rect *size)
  578. {
  579.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  580.  
  581.     if ( myPrivateGlobals == nil )
  582.         return ( kQTIC_paramErr );
  583.         
  584.     size->left = 10;
  585.     size->right = 500;
  586.     size->top = 10;
  587.     size->bottom = 500;
  588.     
  589.     return ( kQTIC_noErr );
  590. }
  591.  
  592. pascal ComponentResult QTICP_GrowWindow(Handle storage, WindowRef theWindow, Rect *old, Rect *new)
  593. {
  594.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  595.  
  596.     if ( myPrivateGlobals == nil )
  597.         return ( kQTIC_paramErr );
  598.  
  599.     return ( kQTIC_noErr );
  600. }
  601.  
  602. pascal ComponentResult QTICP_ZoomWindow(Handle storage, WindowRef theWindow, short windowPart)
  603. {
  604.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  605.  
  606.     if ( myPrivateGlobals == nil )
  607.         return ( kQTIC_paramErr );
  608.  
  609.     return ( kQTIC_noErr );
  610. }
  611.  
  612. pascal ComponentResult QTICP_DoKeyDown(Handle storage, WindowRef theWindow, EventRecord *theEvent)
  613. {
  614.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  615.  
  616.     if ( myPrivateGlobals == nil )
  617.         return ( kQTIC_paramErr );
  618.  
  619.     return ( kQTIC_noErr );
  620. }
  621.  
  622. pascal ComponentResult QTICP_Draw(Handle storage, WindowRef theWindow)
  623. {
  624.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  625.     CGrafPtr            savePort ;
  626.     GDHandle            saveGD ;
  627.  
  628.     if ( myPrivateGlobals == nil )
  629.         return ( kQTIC_paramErr );
  630.         
  631.     GetGWorld( &savePort, &saveGD ) ;
  632.     SetGWorld( (CGrafPtr)(**myPrivateGlobals).window, GetMainDevice() ) ;
  633.     MoveTo(    50, 40);
  634.     TextSize( 24 );
  635.     DrawString( "\pSample Panel" ) ;
  636.     SetGWorld( savePort, saveGD ) ;
  637.     
  638.     return ( kQTIC_noErr );
  639. }
  640.  
  641. pascal ComponentResult QTICP_UpdateCustomMenu(Handle storage, WindowRef theWindow, MenuHandle mHandle)
  642. {
  643.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  644.     ComponentResult        cerr;
  645.     Boolean                connected;
  646.  
  647.     if ( myPrivateGlobals == nil || mHandle == nil )
  648.         return ( kQTIC_paramErr );
  649.  
  650.     AppendMenu( mHandle, (**myPrivateGlobals).menuStrConnected ) ;
  651.  
  652.     return ( kQTIC_noErr );
  653. }
  654.  
  655. pascal ComponentResult QTICP_DoCustomMenu(Handle storage, WindowRef theWindow, MenuHandle mHandle, short selectedItem)
  656. {
  657.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  658.  
  659.     if ( myPrivateGlobals == nil )
  660.         return ( kQTIC_paramErr );
  661.     
  662.     switch ( selectedItem ) {
  663.         case 1:
  664.             SysBeep(50);
  665.             break;
  666.         case 3:
  667.             SysBeep(50);
  668.             SysBeep(50);
  669.             break;
  670.     }
  671.  
  672.     return ( kQTIC_noErr );
  673. }
  674.  
  675. pascal ComponentResult QTICP_GetMenuName(Handle storage, WindowRef theWindow, unsigned char *name)
  676. {
  677.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  678.  
  679.     if ( myPrivateGlobals == nil || name == nil )
  680.         return ( kQTIC_paramErr );
  681.         
  682.     BlockMove("\pSample", name, 7);
  683.     
  684.     return ( kQTIC_noErr );
  685. }
  686.  
  687. pascal ComponentResult QTICP_FinishCustomMenu(Handle storage, WindowRef theWindow, MenuHandle mHandle)
  688. {
  689.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  690.  
  691.     if ( myPrivateGlobals == nil )
  692.         return ( kQTIC_paramErr );
  693.  
  694.     return ( kQTIC_noErr );
  695. }
  696.  
  697. pascal ComponentResult QTICP_Activate(Handle storage, WindowRef theWindow)
  698. {
  699.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  700.  
  701.     if ( myPrivateGlobals == nil )
  702.         return ( kQTIC_paramErr );
  703.  
  704.     return ( kQTIC_noErr );
  705. }
  706.  
  707. pascal ComponentResult QTICP_Deactivate(Handle storage, WindowRef theWindow)
  708.  
  709. {
  710.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  711.  
  712.     if ( myPrivateGlobals == nil )
  713.         return ( kQTIC_paramErr );
  714.  
  715.     return ( kQTIC_noErr );
  716. }
  717.  
  718. //    Any click dialog filter.
  719. pascal Boolean DLOGU_anyClickDialogFilter(DialogRef theDialog, EventRecord *theEvent, short *itemHit)
  720. {
  721.     if ( theEvent->what != mouseDown )
  722.         return ( false );
  723.     else {
  724.         *itemHit = ok;
  725.         return ( true );
  726.     }
  727. }
  728.  
  729. void PANELU_LoadStringFromRsrc( short id, short maxSize, unsigned char *str, unsigned char *defaultStr)
  730. {
  731.     StringHandle    strH;
  732.     long            size;
  733.         
  734.     //    Try string from resource first.
  735.     strH = GetString( id );
  736.     if ( strH && *strH ) {
  737.         size = GetHandleSize((Handle) strH);
  738.         if ( (size-1) > maxSize )
  739.             size = maxSize;
  740.         else if ( size < 0 )
  741.             size = 0;
  742.         HLock((Handle) strH);
  743.         BlockMoveData(*strH, str, size);
  744.         str[0] = size-1;
  745.         ReleaseResource( (Handle) strH );
  746.         
  747.     //    If we can't get resoruce, try default string.
  748.     } else if ( defaultStr != nil ) {
  749.         size = defaultStr[0];
  750.         if ( size > maxSize )
  751.             size = maxSize;
  752.         else if ( size < 0 )
  753.             size = 0;
  754.         BlockMoveData(defaultStr, str, size+1);
  755.         str[0] = size;
  756.         
  757.     //    All else fails, null string.
  758.     } else
  759.         str[0] = 0;
  760. }
  761.